package weapons;

import graphics.*;
import ship.ShipConstants;
import structure.*;
import java.awt.Color;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;

import main.Constants;
import main.Game;

import util.*;

public class Shot extends SObject implements Damaging {
	private Point last;
	
	private int counter = 0;
	
	private double damage;
	
	public Shot(Point p, Point vel, double damage) {
		super(p);
		last = new Point(p);
		this.vel = new Point(vel);
		this.damage = damage;
		// TODO Auto-generated constructor stub
	}

	@Override
	public void draw(MaxGraphics g) {
		Drawing.drawShot(g, cords, last);
	}

	public Shape[] getShape() {
		Shape[] s = { new Line2D.Double(last.getX(), last.getY(), getX(), getY()) };
		return s;
	}
	
	@Override
	public void collide(SObject o) {
		flag();
	}

	
	public void update() {
		last = new Point(getCords());
		counter++;
		if(counter > ShipConstants.SHOT_DURATION) {
			flag();
		}
		super.update();
	}
	
	@Override
	public double getMass() {
		// TODO Auto-generated method stub
		return .1;
	}

	@Override
	public double getRadius() {
		// TODO Auto-generated method stub
		return Math.sqrt(Math.pow(getXVel(), 2) + Math.pow(getYVel(), 2));
	}

	public double getDamage() {
		// TODO Auto-generated method stub
		return damage;
	}

	@Override
	public String toString() {
		return "Shot " + getX() + " " + getY() + " " + last.getX() + " " + last.getY() + " " + damage;
	}
	
}
